import { defineConfig } from 'vite'
import uni from '@dcloudio/vite-plugin-uni'
import vueJsx from '@vitejs/plugin-vue-jsx'
import { dirResolver, DirResolverHelper } from 'vite-auto-import-resolvers'
import AutoImport from 'unplugin-auto-import/vite'
import path from 'path'
// 导入fs模块
import fs from 'fs'

const pathSrc = path.resolve(__dirname, 'src')
export default defineConfig({
  base: '/store/',
  server: {
    hmr: true,
    port: 9999,
    host: true,
    // https: {
    //     cert: fs.readFileSync(path.join(__dirname, '/cert.crt')),
    //     key: fs.readFileSync(path.join(__dirname, '/cert.key')),
    // },
    proxy: {
      '^/proxy': {
        target: 'http://192.168.1.129:9999/', // 后台服务器的源
        changeOrigin: true, // 修改源
        rewrite: (path) => path.replace(/^\/proxy/, ''),
      },
    },
  },
  resolve: {
    alias: {
      '@': path.resolve(__dirname, 'src'),
      '@pluginPackage': path.resolve(__dirname, 'src/pages/pluginPackage'),
    },
  },
  plugins: [
    uni(),
    vueJsx(),
    DirResolverHelper(),
    AutoImport({
      include: [/\.[tj]sx?$/, /\.ts$/, /\.vue$/],
      resolvers: [
        dirResolver({
          target: 'src/composables',
          include: ['useConvert', 'useSafeHeight'],
        }),
      ],
      dts: path.resolve(pathSrc, '../types/auto-imports.d.ts'),
      eslintrc: {
        enabled: true,
        filepath: './types/.eslintrc-auto-import.json',
        globalsPropValue: true,
      },
    }),
  ],
  css: {
    preprocessorOptions: {
      scss: {
        additionalData: `@import "@/assets/css/global.scss";`,
      },
    },
  },
  optimizeDeps: {
    include: ['decimal.js-light', 'qrcode-reader-vue3'],
  },
  build: {
    minify: 'terser',
    terserOptions: {
      compress: {
        // drop_console: true,
        drop_debugger: true,
      },
    },
  },
})
